@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->


<section class="content-header">
    <h1>
        商铺管理
        <small>商铺列表</small>
        <small>添加</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="#">商铺管理</a></li>
        <li ><a href="/admin/shop">商铺列表</a></li>
        <li class="active">添加</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">商铺添加</h3>
                    <div class="pull-right">
                        <a href="{{Route('admin.shop.index')}}" type="button" class="btn btn-block btn-success btn-xs"><i class="icon  glyphicon glyphicon glyphicon-menu-left"></i> 返回</a>
                    </div>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                {!! Form::model($shop,['route'=>'admin.shop.store','class'=>'form-horizontal'])  !!}
                    {!! Form::hidden('back_url',@$_SERVER['HTTP_REFERER']) !!}
                    <div class="box-body">
                        <div class="form-group @if($errors->has('shop_name')) has-error   @endif">
                            <label class="col-sm-2 control-label" for="exampleInputEmail1">商铺名称：</label>
                            <div class="col-sm-2">
                            {!! Form::text('shop_name',old('shop_name'),array('class'=>'form-control','placeholder'=>'商铺名称'))!!}
                            </div>
                            <div class="col-sm-2">
                            @if($errors->has('shop_name'))
                                <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('shop_name')}}</label>
                            @endif
                            </div>
                        </div>
 

                        <div class="form-group @if($errors->has('shop_logo')) has-error   @endif">
                        <label class="col-sm-2 control-label" class="col-sm-2 control-label" for="exampleInputPassword1">商铺LOGO：</label>

                            <div class="col-sm-2" style="width: 194px;">
                                <div class="image-uploader">
                                    <style>
                                        .upload-btn{
                                            display: block; width:48px;height:30px;position: absolute;filter:alpha(opacity=0);-moz-opacity:0;-khtml-opacity: 0;opacity: 0;
                                        }
                                    </style>
                                    <!-- /.box-header -->
                                    <div class="box-body">

                                        <div style="width: 145px;display: block;">
                                            <img class="image" style="width: 145px;height: auto;; padding: 1px;" src="@if (old('image_url')) {{old('image_url')}} @else http://placehold.it/180x72 @endif"/>
                                            <input type="hidden" id="image_url" name="image_url" value="{{old('image_url')}}">
                                        </div>
                                        <div class="message" style="width: 145px;height: 145px; display: block;position: absolute; padding: 5px; top:0px; color: red; text-align: center; line-height: 145px;display: none;">

                                        </div>

                                        <div class="progress progress-xxs" style="position: absolute;width: 140px; left:13px; display: none;">
                                            <div class="progress-bar progress-bar-default " role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
                                            </div>
                                        </div>
                                    </div>
                                    <!-- /.box-body -->
                                    <div class="box-footer" style="position: relative">

                                        <button class="btn btn-sm btn-default btn-flat pull-left" type="button">上传</button>
                                        {!! Form::file('file',['class'=>'upload-btn','id'=>'fileupload','type'=>'file','data-url'=>'/admin/file_upload']) !!}
                                        {!! Form::hidden('shop_logo',old('shop_logo'),['id'=>'thumb']) !!}

                                        <button class="btn  btn-sm btn-danger btn-flat pull-right" type="button">删除</button>
                                    </div>
                                </div>
                                <!-- /.box -->
                            </div>

                            @if($errors->has('shop_logo'))
                                <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('activity_thumb')}}</label>
                            @endif
                        </div>


                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="exampleInputPassword1">描述：</label>
                            <div class="col-sm-6">
                            {!! Form::textarea('shop_desc',old('shop_desc'),array('class'=>'form-control','placeholder'=>'请填写描述','rows'=>3))!!}
                            </div>
                        </div>

                        <div class="form-group @if($errors->has('is_show')) has-error   @endif">
                            <label class="col-sm-2 control-label" for="exampleInputPassword1">是否展示：</label>
                            <div class="col-sm-2">
                            {!! Form::select('is_show',['0'=>'不展示','1'=>'展示'],1,['class'=>'form-control'])!!}
                            </div>
                            <div class="col-sm-2">
                            @if($errors->has('is_show'))
                                <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('is_show')}}</label>
                            @endif
                            </div>
                        </div>



                        <div class="J-selWrap hide form-group">
                            <label class="J-label col-sm-2 control-label">适用范围</label>
                            <div class="J-type col-sm-3">

                                {{-- {!! Form::select('',$typeArr,old('type'),['data-type'=>@$discounts->type , 'data-selected'=>@$goods , 'data-placeholder'=>'请选择' , 'class'=>'J-sel2 form-control select2 select2-hidden-accessible-', 'multiple'])!!} --}}

                                {!! Form::select('',$user_arr,old('user_id'),['data-type'=>@$user_id , 'data-selected'=>@$user_id , 'data-placeholder'=>'请选择用户' , 'class'=>'J-sel2 form-control select2 select2-hidden-accessible-', 'multiple'])!!}

                            </div>
                        </div>
                        <input id="selectResult" class="sr-only" type="text" name="use_id_str" value="{{@$use_id_str}}">
                        <div class="J-resultList form-group">
                            <label class="col-sm-2 control-label">选择用户</label>
                            <div class="col-sm-3">
                                <div class="add-goods">
                                    <button type="button" class="form-control" data-toggle="modal" data-target="#UserModal">请选择用户</button>
                                </div>
                                <div class="goods-list hide" style="width: 800px;">
                                    <table class="table table-bordered">

                                        <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>用户名</th>
                                            <th>手机</th>
                                            <th>邮箱</th>
                                            <th>最后登录时间</th>
                                            <th>最后登录IP</th>
                                            <th>积分</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        </tbody>
                                    </table>
                                </div>

                                @if($errors->has('user'))
                                    <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i> {{$errors->first('user')}}</label>
                                @endif
                            </div>
                        </div>


                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <div class="form-group no-padding">
                            <label class="col-sm-2 control-label">&nbsp;</label>
                            <div class="col-sm-3">
                                <button type="submit" class="btn btn-primary">保存</button>
                            </div>
                        </div>
                    </div>
                {!! Form::close()  !!}
            </div>
            <!-- /.box -->
        </div>
    </div>



</section>
<!-- /.content -->


<div id="UserModal" class="modal fade">
    <div class="modal-dialog  modal-lg">
        <div class="modal-content box">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">选择用户</h4>
            </div>


            <div class="modal-body">
                <form class="J-search form-search form-inline" action="/admin/user/get_user" method="get" >

                    <!-- <div class="form-group">
                        <label class="sr-only">所有用户</label>

                        {{-- {!! Form::select('user_id',$user_arr,@$_GET['user_id'],['class'=>'J-select form-control select2 select2-hidden-accessible','data-placeholder'=>'请选择用户'])!!} --}}
                    </div> -->
                    <div class="form-group">
                        <label class="sr-only">用户名</label>
                        <input type="text" name="user_name" class="form-control" placeholder="请输入用户名称">
                    </div>


                    <button type="submit" class="J-searchBtn btn btn-primary">搜索</button>


                </form>

                <div class="box-body table-responsive" style="padding: 30px 0 0 0;">

                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th class="text-center" style="width: 60px">选择</th>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>手机</th>
                            <th>邮箱</th>
                            <th>最后登录时间</th>
                            <th>最后登录IP</th>
                            <th>积分</th>
                        </tr>
                        </thead>
                        <tbody class="J-userList"></tbody>

                    </table>
                </div>
                <div class="box-footer">
                    <!-- 分页 -->
                    <div class="J-page pull-right no-margin-pager">
                        <ul class="pagination"></ul>
                    </div>
                </div>
            </div>


            <div class="J-footer modal-footer hide">
                <div class="J-result content text-left" style="min-height: 50px;"></div>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="J-ok btn btn-primary">确定</button>
            </div>

            <div class="J-loading overlay">
                <i class="fa fa-refresh fa-spin"></i>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<template id="userTrTpl">
    <tr id="user-list-tr${id}" class="J-tr" data-id="${id}">
        <td class="checkbox-wrap text-center">
            <input class="J-check" type="checkbox" value="${id}" ${is_checked}>
        </td>
        <td>${id}</td>
        <td>${user_name}</td>
        <td>${phone}</td>
        <td>${email}</td>
        <td>${last_login_time}</td>
        <td>${last_login_ip}</td>
        <td>${point}</td>
    </tr>
</template>

<script src="{{ asset ("/components/blueimp-file-upload/js/vendor/jquery.ui.widget.js") }}"></script>
<script src="{{ asset ("/components/blueimp-file-upload/js/jquery.iframe-transport.js") }}"></script>
<script src="{{ asset ("/components/blueimp-file-upload/js/jquery.fileupload.js") }}"></script>

<!-- Select2 -->
<script type="text/javascript" src="{{ asset("/components/AdminLTE/plugins/select2/select2.full.min.js") }}"></script>
<script src="{{ asset("/components/AdminLTE/plugins/daterangepicker/moment.min.js") }}"></script>
<script src="{{ asset("/components/AdminLTE/plugins/daterangepicker/daterangepicker.js") }}"></script>


<script src="{{ asset("/js/tools.js") }}"></script>
<script src="{{ asset("/js/searchUser.js") }}"></script>
<script>
    $(function () {
        $('.image-uploader').each(function(k,imageUploader){
            var wrapper = $(imageUploader);//盒子
            var uploadBtn = wrapper.find('#fileupload');
            var imageFile = wrapper.find('.image');
            var progress = wrapper.find('.progress');
            var progressBar = progress.find('.progress-bar');
            var inputFile = wrapper.find('#thumb');
            var imageUrl = wrapper.find('#image_url');
            var message = wrapper.find('.message');

            uploadBtn.click(function(){
                progressBar.css('width', 0 + '%');
                imageFile.attr('src','http://placehold.it/180x72');
                inputFile.val('');
                message.hide();

            });
            wrapper.find('.btn-danger').click(function(){
                progressBar.css('width', 0 + '%');
                imageFile.attr('src','http://placehold.it/180x72');
                inputFile.val('');
                message.hide();

            });

            uploadBtn.fileupload({
                dataType: 'json',
                headers:{'X-CSRF-TOKEN':'{{csrf_token()}}'},
                add: function (e, data) {
                    data.submit();
                },
                progressall: function (e, data) {
                    progress.fadeIn();
                    var percent = parseInt(data.loaded / data.total * 100, 10);
                    if (progress==1){
                        progress.show()
                    }
                    progressBar.css('width', percent + '%');
                    setTimeout(function () {
                        progress.fadeOut();
                    }, 500);
                },
                done: function (e, data) {
                    imageFile.attr('src',data.result.url);
                    inputFile.val(data.result.id);
                    imageUrl.val(data.result.url);
                },
                complete:function(){
                }
            });
        });
    });
</script>
@endsection